package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.TFreightBillInfo;
import com.ruoyi.finance.service.ITFreightBillInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运费账单Controller
 * 
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/finance/freight")
public class TFreightBillInfoController extends BaseController
{
    @Autowired
    private ITFreightBillInfoService tFreightBillInfoService;

    /**
     * 查询运费账单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:freight:list')")
    @GetMapping("/list")
    public TableDataInfo list(TFreightBillInfo tFreightBillInfo)
    {
        startPage();
        List<TFreightBillInfo> list = tFreightBillInfoService.selectTFreightBillInfoList(tFreightBillInfo);
        return getDataTable(list);
    }

    /**
     * 导出运费账单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:freight:export')")
    @Log(title = "运费账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFreightBillInfo tFreightBillInfo)
    {
        List<TFreightBillInfo> list = tFreightBillInfoService.selectTFreightBillInfoList(tFreightBillInfo);
        ExcelUtil<TFreightBillInfo> util = new ExcelUtil<TFreightBillInfo>(TFreightBillInfo.class);
        util.exportExcel(response, list, "运费账单数据");
    }

    /**
     * 获取运费账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:freight:query')")
    @GetMapping(value = "/{freightBillId}")
    public AjaxResult getInfo(@PathVariable("freightBillId") Long freightBillId)
    {
        return success(tFreightBillInfoService.selectTFreightBillInfoByFreightBillId(freightBillId));
    }

    /**
     * 新增运费账单
     */
    @PreAuthorize("@ss.hasPermi('finance:freight:add')")
    @Log(title = "运费账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFreightBillInfo tFreightBillInfo)
    {
        tFreightBillInfo.setCreateBy(getNickName());
        return toAjax(tFreightBillInfoService.insertTFreightBillInfo(tFreightBillInfo));
    }

    /**
     * 修改运费账单
     */
    @PreAuthorize("@ss.hasPermi('finance:freight:edit')")
    @Log(title = "运费账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFreightBillInfo tFreightBillInfo)
    {
        tFreightBillInfo.setUpdateBy(getNickName());
        return toAjax(tFreightBillInfoService.updateTFreightBillInfo(tFreightBillInfo));
    }

    /**
     * 删除运费账单
     */
    @PreAuthorize("@ss.hasPermi('finance:freight:remove')")
    @Log(title = "运费账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{freightBillIds}")
    public AjaxResult remove(@PathVariable Long[] freightBillIds)
    {
        return toAjax(tFreightBillInfoService.deleteTFreightBillInfoByFreightBillIds(freightBillIds));
    }
}
